package com.wc.fortnight_blue_bridge.Q231111.Q6278;

import java.util.HashMap;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/11/11 21:54
 * @description
 * 被替换的身份证
 * https://www.lanqiao.cn/problems/6278/learning/?contest_id=146
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        HashMap<Character, Integer> map = new HashMap<>();
        map.put('3', 1);
        map.put('4', 2);
        map.put('5', 3);
        map.put('6', 4);
        map.put('7', 5);
        map.put('8', 6);
        map.put('9', 7);
        map.put('X', 8);
        map.put('J', 9);
        map.put('Q', 10);
        map.put('K', 11);
        map.put('A', 12);
        map.put('2', 13);
        map.put('M', 14);
        map.put('F', 15);

        while (n-- > 0) {
            String[] ss = sc.nextLine().split(" ");
            String pre = ss[0];
            String cur = ss[1];
            if (pre.charAt(0) == pre.charAt(1) || pre.equals("MF") || pre.equals("FM")) {
                System.out.println("ShallowDream");
            } else if (cur.equals("MF") || cur.equals("FM")) {
                System.out.println("Joker");
            } else {
                int maxPre = Math.max(map.get(pre.charAt(0)),map.get(pre.charAt(1)));
                int maxCur = Math.max(map.get(cur.charAt(0)),map.get(cur.charAt(1)));
                if (maxPre >= maxCur){
                    System.out.println("ShallowDream");
                }else {
                    System.out.println("Joker");
                }
            }
        }
    }
}
